<template>
  <div>
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="120px"
    >
      <el-form-item label="供应商名称" prop="corporateName">
        <el-input
          v-model="queryParams.corporateName"
          placeholder="请输入供应商名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="统一信用代码" prop="unifiedCreditCode">
        <el-input
          v-model="queryParams.unifiedCreditCode"
          placeholder="请输入统一信用代码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <!-- <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:supplier:remove']"
        >批量删除</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row> -->

    <el-table
      v-loading="loading"
      :data="supplierList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column label="供应商名称" align="center" prop="corporateName" />
      <el-table-column
        label="统一信用代码"
        align="center"
        prop="unifiedCreditCode"
      />
      <el-table-column label="法人" align="center" prop="legalPerson" />
      <el-table-column label="法人电话" align="center" prop="legalPhone" />
      <el-table-column label="地址" align="center" prop="address" />
      <el-table-column
        label="上传的营业执照复印件"
        align="center"
        prop="businessLicense"
      >
        <template slot-scope="scope">
          <el-image 
            v-if="scope.row.businessLicense"
    style="width: 100px; height: 100px"
    :src="baseUrl + scope.row.businessLicense" 
    :preview-src-list="srcList"
    @click="vbs(baseUrl + scope.row.businessLicense)">
  </el-image>
          <span v-else>暂无数据</span>
        </template>
      </el-table-column>
      <el-table-column label="公司类别" align="center" prop="type" :show-overflow-tooltip="true" >
</el-table-column>
      <el-table-column label="审核状态" align="center" prop="state">
        <template slot-scope="scope">
          <el-tag
            type="danger"
            v-if="scope.row.state === '0'"
            style="margin-left: 10px"
            >待审核</el-tag
          >
          <el-tag
            type="success"
            v-else-if="scope.row.state === '1'"
            style="margin-left: 10px"
            >审核通过</el-tag
          >
          <el-tag
            type="warning"
            v-else-if="scope.row.state === '2'"
            style="margin-left: 10px"
            >审核未通过</el-tag
          >
        </template>
      </el-table-column>
      <el-table-column label="经办人" align="center" prop="handledBy" />
      <el-table-column
        label="经办人联系电话"
        align="center"
        prop="handledByPhone"
      />
      <el-table-column label="邮箱" align="center" prop="email" />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="handleExamine(scope.row)"
            >审核</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <DialogView
      :dialogTitle="reViewedDialog.dialogTitle"
      :visible="reViewedDialog.visible"
      @submitData="submitData"
      @handleClose="handleClose"
    >
      <span style="font-size: 20px"
        >供应商{{ rowData.corporateName }}审批结果：</span
      ><el-select v-model="form.state" placeholder="请选择">
        <el-option
          v-for="e in stateOptions"
          :key="e.value"
          :label="e.label"
          :value="e.value"
        ></el-option>
      </el-select>
    </DialogView>
  </div>
</template>

<script>
import { listSupplier, reviewedSupplier } from "@/api/supplier/api";

export default {
  name: "unReviewed",
  data() {
    return {
      srcList:[],
      stateOptions: [
        {
          value: "1",
          label: "通过",
        },
        {
          value: "2",
          label: "不通过",
        },
      ],
      rowData: {},
      reViewedDialog: {
        dialogTitle: "审批",
        visible: false,
      },
      baseUrl: process.env.VUE_APP_BASE_API,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 供应商信息表格数据
      supplierList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        corporateName: null,
        unifiedCreditCode: null,
        state: "0",
      },
      // 表单参数
      form: {
        state: "",
      },
      // 表单校验
      rules: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    vbs(val){
      this.srcList = []
      this.srcList.push(val)
    },
    /** 查询供应商信息列表 */
    getList() {
      this.loading = true;
      listSupplier(this.queryParams).then((response) => {
        this.supplierList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        corporateName: null,
        unifiedCreditCode: null,
        type: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.supplierId);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 审核按钮操作 */
    handleExamine(row) {
      this.rowData = row;
      this.reViewedDialog.visible = true;
    },
    handleClose() {
      this.reViewedDialog.visible = false;
    },
    submitData() {
      const data = { ...this.form };
      data.supplierId = this.rowData.supplierId;
      reviewedSupplier(data).then((res) => {
        this.$modal.msgSuccess("审批成功");
        this.reViewedDialog.visible = false;
      this.getList();
      }).catch((err) =>{
        this.reViewedDialog.visible = false;
      this.getList();
      })
      // this.reViewedDialog.visible = false;
      // this.getList();
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "system/supplier/export",
        {
          ...this.queryParams,
        },
        `supplier_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
